package builder

import "fmt"

type Computer struct {
	Cpu      string
	Ram      string
	usbCount int
	keyboard string
	display  string
}

func NewComputer(cpu, ram string) *Computer {
	return &Computer{Cpu: cpu, Ram: ram}
}
func (th *Computer) Print() {
	fmt.Println(fmt.Sprintf("CPU:%v, Ram:%s, usbCount:%d, keyboard:%s, display:%s",
		th.Cpu, th.Ram, th.usbCount, th.keyboard, th.display))
}

// 抽象构建者接口
type ComputerBuilder interface {
	SetUsbCount()
	SetKeyboard()
	SetDisplay()
	GetComputer() *Computer
}

// 指导者类
type ComputerDirector struct {
	builder ComputerBuilder
}

func NewComputerDirector(builder ComputerBuilder) *ComputerDirector {
	return &ComputerDirector{builder}
}

func (th *ComputerDirector) makeComputer() {
	th.builder.SetUsbCount()
	th.builder.SetKeyboard()
	th.builder.SetDisplay()
}

// 苹果电脑构造者
type MacComputerBuilder struct {
	c *Computer
}

func (th *MacComputerBuilder) SetUsbCount() {
	th.c.usbCount = 2
}

func (th *MacComputerBuilder) SetKeyboard() {
	th.c.keyboard = "苹果键盘"
}

func (th *MacComputerBuilder) SetDisplay() {
	th.c.display = "苹果显示器"
}

// 联想电脑构造者
func (th *MacComputerBuilder) GetComputer() *Computer {
	return th.c
}

type LenovoComputerBuilder struct {
	c *Computer
}

func (th *LenovoComputerBuilder) SetUsbCount() {
	th.c.usbCount = 4
}

func (th *LenovoComputerBuilder) SetKeyboard() {
	th.c.keyboard = "联想键盘"
}

func (th *LenovoComputerBuilder) SetDisplay() {
	th.c.display = "联想显示器"
}

func (th *LenovoComputerBuilder) GetComputer() *Computer {
	return th.c
}
